package com.future.mayi.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.future.baselib.utils.CommonUtils;
import com.future.mayi.R;
import com.future.mayi.activity.KeepGoodsInfoActivity;
import com.future.mayi.model.KeepCateModel;
import com.future.mayi.model.KeepGoodsModel;
import com.future.mayi.model.interfaces.OnKeepGoodItemClickListener;
import com.future.mayi.view.KeepGoodsListView;
import com.future.mayi.view.xrecyclerview.XRecyclerView;

import butterknife.BindView;
import butterknife.ButterKnife;

public class KeepGoodsAdapter extends BaseRecyclerViewAdapter<KeepCateModel> implements OnKeepGoodItemClickListener {

    private int titleHeight;

    public KeepGoodsAdapter(Context context, XRecyclerView recyclerView) {
        super(context, null, recyclerView);
        titleHeight = (int) (CommonUtils.getScreenSize(context)[0] * 0.4f);
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(getView(parent, R.layout.layout_keep_goods_item));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
        ViewHolder holder = (ViewHolder) viewHolder;
        KeepCateModel model = getItem(position);
        loadImg(holder.ivTitle, model.getCate_img());
        holder.ivTitle.getLayoutParams().height = titleHeight;
        holder.keepGoodsView.setList(model.getType_list());
        holder.keepGoodsView.setListener(this);
    }

    @Override
    public void onItemClick(KeepGoodsModel model) {
        Intent intent=new Intent(mContext, KeepGoodsInfoActivity.class);
        intent.putExtra("model",model);
        mContext.startActivity(intent);
    }


    class ViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.iv_title)
        ImageView ivTitle;
        @BindView(R.id.keep_goods_view)
        KeepGoodsListView keepGoodsView;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}
